!{include file='common/iheader.htm'}
<style>
	form{display:none;}
</style>
<div id="i_nav">
	<h3 class="page_title">!{$cate_name}分类管理</h3>
	<a class="button" href="javascript:void(0)" onclick="edit()">添加分类</a>
</div>
<ul class="list_view">
	!{foreach from=$cates item=cate key=id}
	<li>
		<strong>!{$cate.name}</strong>
		<div class="opt_div">
			<a href="javascript:void(0)" onclick="edit(this, '!{$id}', '!{$cate.parent}')">修改</a> 
			<a href="javascript:void(0)" onclick="del('!{$id}')">删除</a>
		</div>
	</li>
	!{foreachelse}
	<li>暂无分类</li>
	!{/foreach}
</ul>

<form method="post" class="form_box ajax_form" id="cate_edit_form">
	<div class="form_item">
		<strong>分类名称：</strong>
		<div><input class="text_input" maxlength="50" type="text" name="name" value=""/></div>
		<p>(分类名称长度应该在1至50之间)</p>
	</div>
	<div class="form_item">
		<strong>上级分类：</strong>
		<div>
			<select name="parent">
				<option value="0">--顶级分类--</option>
				!{html_options options=$options}
			</select>
		</div>
	</div>
	<div class="form_item form_btn_item">
		<input type="hidden" name="id" value="0"/>
		<input type="hidden" name="app" value="file"/>
		<input type="hidden" name="act" value="cate"/>
		<input type="hidden" name="cate" value="!{$cate_id}"/>
		<input class="button submit_btn" type="button" value="保存" />
		<input class="button" type="button" value="取消" onclick="$('form').slideUp()"/>
	</div>
</form>
<script>
	$(function(){
		$("#cate_edit_form").ajax_form({
			submit_btn : '.submit_btn'
		});
	});
	function edit(obj, id, parent){
		$('form').slideDown();
		if(obj!=null){
			var name = $(obj).parents('li').find('strong').html().replace(/　/ig, "");
			$('form input[name="name"]').val(name);
			$('form select').val(parent);
			$('form input[name="id"]').val(id);
		}else{
			$('form input[name="name"]').val('');
			$('form select').val(0);
			$('form input[name="id"]').val(0);
		}
	}

	function del(id){
		if(confirm('是否继续删除此分类？')){
			$.get('/manager.php?app=file&act=cate_del&cate=!{$cate_id}&id=' + id, function(data){
				var json = eval('('+data+')');
				alert(json.info);
				if(json.result){
					window.location.reload();
				}
			});
		}
	}
</script>
!{include file='common/ifooter.htm'}